package com.china08.yxyapi.api.manage.tec.teaching.continuedu.mytask;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.entity.mg.continuedu.YxyContinueduStatisticsUserTask;
import com.china08.yxyapi.model.YxyApiReqModel;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.repository.mg.continuedu.YxyContinueduStatisticsUserTaskRepository;

/**
 * 
 * @annotation: 继续教育-我的任务-用户任务统计查询
 * @author: yaoguanglin
 */
@CrossOrigin
@RestController
public class YxyContinueduStatisticsSchController extends YxyApiBaseController {

    @Autowired
    private YxyContinueduStatisticsUserTaskRepository yxyContinueduStatisticsUserTaskRepository;

    @RequestMapping(value = "/api_yw/manage/tec/teaching/continuedu/mytask/statistics/sch", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public RespModel process(HttpServletRequest request, HttpServletResponse response,
            @RequestBody(required = false) ReqModel reqModel) {

        String userId = getProfile(request, response).getId();

        YxyContinueduStatisticsUserTask userStatistics = yxyContinueduStatisticsUserTaskRepository.findById(userId);
        RespModel model = new RespModel();

        if (userStatistics != null) {
            model.finishCount = userStatistics.getFinishCount();
            model.lessonCount = userStatistics.getLessonCount();
            model.myScore = userStatistics.getMyScore();
        } else {
            model.finishCount = 0l;
            model.lessonCount = 0l;
            model.myScore = 0l;
        }
        return model;
    }

    protected static class ReqModel extends YxyApiReqModel {

    }

    protected static class RespModel extends YxyApiRespModel {

        public Long finishCount;// 我完成的任务数量

        public Long myScore;// 我的总分数

        public Long lessonCount;// 我的学习课程数量

    }
}
